using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Users;

using WL.Think.Abp.EntityFrameworkCore;

namespace WL.Think.Abp.Repositories;

public abstract class EfCoreKeyRepository<TDbContext, TEntity,TKey> : EfCoreRepository<TDbContext, TEntity, TKey>, IEfCoreKeyRepository<TEntity, TKey>
    where TEntity : class, IEntity<TKey>
    where TDbContext : AppDbContextBase<TDbContext>
{
    /// <summary>
    /// 当前用户
    /// </summary>
    protected ICurrentUser CurrentUser => LazyServiceProvider.LazyGetRequiredService<ICurrentUser>();

    protected EfCoreKeyRepository(IDbContextProvider<TDbContext> dbContextProvider) : base(dbContextProvider)
    {
         
    }

    /// <summary>
    /// 关闭软删除,会直接删除数据库数据，注意执行完成后要记得恢复，使用 using 操作
    /// </summary>
    /// <returns></returns>
    protected IDisposable CloseSoftDelete()
    {
        return DataFilter.Disable<ISoftDelete>();
    }

    /// <summary>
    /// 关闭软删除
    /// </summary>
    /// <param name="action"></param>
    protected void CloseSoftDelete(Action action)
    {
        using (DataFilter.Disable<ISoftDelete>())
        {
            action?.Invoke();
        }
    }
}


public abstract class EfCoreKeyRepository<TDbContext, TEntity> : EfCoreRepository<TDbContext, TEntity, Guid>, IEfCoreKeyRepository<TEntity>
    where TEntity : class, IEntity<Guid>
    where TDbContext : AppDbContextBase<TDbContext>
{
    protected EfCoreKeyRepository(IDbContextProvider<TDbContext> dbContextProvider) : base(dbContextProvider)
    {

    }
}